<template>
	<view class="my-page">
		<view class="upload-form">
			<!-- <view class="password-old password">
				<input v-model="resetForm.passwordold" type="password" class="uni-input" placeholder="输入旧密码" />
			</view> -->
			<view class="item">
				<upload-image tip='' :imageSrc.sync='fromData.image' :isJustShow='isJustShow' ></upload-image>
			</view>
		</view>
		<div class="login-btn box" @click="submit">查 询</div>
		<view class="text-info" v-if="showTextInfo">
			<icon class="clear" type="clear" size="20" color="red" @click="clear" />
			<view class="item">
				<view class="item-info" v-for="(item, i) in msg " :key="i">
					名字：{{item.name}}， 准确率： {{filterScore(item.score)}}%;
					<!-- <view></view>
					<view></view> -->
				</view>	
				
			</view>
		</view>
	</view>
</template>

<script>
import {
		recongnizeAnimal 
	} from '../../untils/api.js'
	export default {
		name:'identify',
		data(){
			return {
				isJustShow:false,
				showTextInfo:false,
				fromData:{
					image:''
				},
				msg:null
			}
		},
		methods:{
			filterScore(score){
              return parseFloat(score*100).toFixed(2)
			},
			submit(){
				if(!this.fromData.image){
					 uni.showToast({
						title:'请上传照片',
						icon:'none'
					})
					return false
				}
                uni.showLoading({
					title:'查询中……',
					mask: true
				})
				// const satoken  = uni.getStorageSync('satoken') || '';
				uni.uploadFile({
					url: 'https://iot.shunongyiqi.com/admin-api/zy/equipment/recognizeAnimal', 
					filePath: this.fromData.image,
					name: 'image',
					header:{},
					success: (uploadFileRes) => {
						console.log(uploadFileRes.data)
						// if(uploadFileRes.data){
							const data = JSON.parse(uploadFileRes.data)
							this.msg = JSON.parse(data.data).result
						// }
					},
					complete:() => {
						uni.hideLoading()
						this.showTextInfo = true
					}
				});
				// recongnizeAnimal(this.fromData).then((res) => {
				// 	console.log(res)
				// })
				
			},
			clear(){
				this.showTextInfo = false
				this.fromData.image = ''
			}
		},
		onLoad() {
			
		}
	}
</script>

<style lang="scss" scoped>
	.login-btn {
		margin-top: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 45px;
		background: #00B23C;
		border-radius: 8px;
		font-weight: 500;
		font-size: 16px;
		color: #FFFFFF;
	}
.my-page {
	height: 100%;
	background: #F4F5F5;
	.upload-form {
		margin-top: 14rpx;
		width: 96%;
		margin: 14rpx auto 0;
		.item {
			// height: 114rpx
			background: #fff;
			display: flex;
			align-items: center;
			.item-info{
				display: flex;
				justify-content: flex-start;
				align-items: center;
				line-height: 40rpx;
			}
		}
		
	}
}
.text-info{
	width: 96%;
	margin: 100rpx auto 20rpx;
	background: #fff;
	border-radius: 20rpx;
	padding: 30rpx;
	padding-top: 50rpx;
	box-sizing: border-box;
	position: relative;
	.clear{
		position: absolute;
		right: 20rpx;
		top: 10rpx;
	}
}
</style>